﻿Option Explicit On
Option Strict On

Imports LogginsLogDSTableAdapters

Partial Class Account_EmailVerification
    Inherits System.Web.UI.Page
    Dim u As MembershipUser
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not Request.QueryString("id") Is Nothing Then
            Dim guid As New Guid(Request.QueryString("id"))
            u = Membership.GetUser(guid)
            If u Is Nothing Then
                FormsAuthentication.SignOut()
                Response.Redirect("~/default.aspx")
            End If

            lblUser.Text = u.UserName
            If Not u.IsApproved Then

            End If

            Dim getuseracccheckdatacheckTA As New usp_UserCheckTableAdapter()
            Dim getuseracccheckdatacheckDT As LogginsLogDS.usp_UserCheckDataTable

            Try
                getuseracccheckdatacheckDT = getuseracccheckdatacheckTA.GetData(CType(u.ProviderUserKey, Global.System.Guid))
            Catch ex As Exception
                Throw ex
            End Try


            For Each getuseracccheckdataRow As LogginsLogDS.usp_UserCheckRow In getuseracccheckdatacheckDT
                If Not getuseracccheckdataRow.EmailConfirmed AndAlso u.IsApproved Then
                    lblAdminBanned.Text = "Sorry, your account has been disabled by the Site Administrator."
                    lblAdminBanned.Visible = True
                    Button1.Visible = False
                ElseIf getuseracccheckdataRow.EmailConfirmed AndAlso u.IsApproved Then
                    FormsAuthentication.SetAuthCookie(u.UserName, False)
                    Response.Redirect("~/private/default.aspx") 'go to the user checks page.
                ElseIf Not getuseracccheckdataRow.EmailConfirmed AndAlso Not u.IsApproved Then
                    If u.IsApproved Then
                        FormsAuthentication.SetAuthCookie(u.UserName, False)
                        Response.Redirect("~/private/default.aspx") 'go to the user checks page.
                    Else
                        u.IsApproved = True
                        Membership.UpdateUser(u)
                        Dim getuseracccheckdataTA As New usp_UserCheckTableAdapter()
                        Dim getuseracccheckdataDT As LogginsLogDS.usp_UserCheckDataTable

                        Try
                            getuseracccheckdataDT = getuseracccheckdataTA.GetData(CType(u.ProviderUserKey, Global.System.Guid))
                        Catch ex As Exception
                            Throw ex
                        End Try

                        For Each getuseracccheckdatacheckRow As LogginsLogDS.usp_UserCheckRow In getuseracccheckdataDT
                            Dim emailverupdate As New LogginsLogDSTableAdapters.SPTableAdapter()
                            emailverupdate.EmailVerification(CType(u.ProviderUserKey, Global.System.Guid))
                        Next
                        FormsAuthentication.SetAuthCookie(u.UserName, False)
                        'Response.Redirect("~/private/default.aspx") 'go to the user checks page.
                    End If
                Else
                    lblAdminBanned.Text = "Sorry, your account has been disabled by the Site Administrator."
                End If

            Next

        Else
            Response.Redirect("~/default.aspx")
        End If

    End Sub

    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        Response.Redirect("~/private/default.aspx") 'go to the user checks page.
    End Sub

End Class
